home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / BoxMooV / sources / BoxPaint_main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  5.5 KB  |  241 lines  |  [TEXT/CWIE]

  1. /*  main.c                                                                            
  2.                                                                                     
  3.   This is BoxPaint, a sample app designed to show how getting UV data from
  4.   a pick object can be used to draw on a texture. This app does not have        
  5.   graceful error handling - it's purpose is to demonstrate UV picking.                                                                        
  6.                                                                                     
  7.   Michael Bishop - August 21 1996                                                    
  8.   Nick Thompson
  9.   Robert Dierkes                                                                                
  10.   (c)1994-96 Apple Computer Inc., All Rights Reserved                                
  11.  
  12. */
  13.  
  14. /*  system headers */
  15. #include <Devices.h>
  16. #include <Dialogs.h>
  17. #include <DiskInit.h>
  18. #include <Events.h>
  19. #include <Fonts.h>
  20. #include <Menus.h>
  21. #include <PictUtils.h>
  22. #include <QDOffScreen.h>
  23. #include <QuickDraw.h>
  24. #include <SegLoad.h>
  25. #include <StandardFile.h>
  26. #include <TextEdit.h>
  27.  
  28. #include    "BoxPaint_main.h"
  29. #include    "BoxPaint_utility.h"
  30. #include    "BoxPaint_menu.h"
  31. #include    "BoxMooV_window.h"
  32. #include    "BoxMooV_event.h"
  33. #include    "BoxMooV_document.h"
  34.  
  35. /* -------------------------------------------------------------------------------------------
  36. ** function prototypes
  37. */
  38.  
  39. static void InitToolbox( void ) ;
  40. static void Main_EventLoop( void ) ;
  41. static void    Main_Init( short mBarResourceID, short numMoremasters);
  42. static void    Main_Destroy( void );
  43.  
  44.  
  45. /* -------------------------------------------------------------------------------------------
  46. ** Global Variables
  47. */
  48.  
  49. Boolean         gQuitFlag         = false ;
  50. Boolean            gForeground        = true ;
  51. short            gTicks            = 1 ;
  52.  
  53. /* -------------------------------------------------------------------------------------------
  54. **  main() 
  55. **  entry point for the application, initialize the toolbox, initialize QuickDraw 3D 
  56. **  and enter the main event loop.  On exit from the main event loop, we want to call 
  57. **  the QuickDraw 3D exit function to clean up QuickDraw 3d. 
  58. */
  59.  
  60. void main( void ) 
  61. {
  62.     Main_Init( kMBARResID, 5 ) ;            /* initialise the toolbox, load our menubar */
  63.  
  64.     Main_EventLoop() ;
  65.     
  66.     /* tear down any we allocated */
  67.     Main_Destroy() ;    
  68.     
  69.     /* and bail */
  70.     ExitToShell() ;
  71. }
  72.  
  73. /*    -------------------------------------------------------------------------------------------
  74. **    Main_Init
  75. **    Initialize our environment, pass in the mbar resource ID, and also the number of calls 
  76. **    to make to moremasters
  77. */
  78.  
  79. void Main_Init( short mBarResourceID, short numMoremasters)
  80. {
  81.     Handle        menuBar = nil;
  82.     short        loopCounter ;
  83.     TQ3Status    myStatus ;
  84.     
  85.     MaxApplZone() ;        /* max out the apps heap */
  86.     
  87.     for( loopCounter = 0; loopCounter < numMoremasters ; loopCounter++ )
  88.         MoreMasters() ;
  89.         
  90.     InitToolbox() ;
  91.     
  92.     /* initialize anything else we need to */
  93.     
  94.     /* init QuickDraw 3D, open a connection to the QuickDraw 3D library */
  95.     myStatus = Q3Initialize();
  96.  
  97.     if ( myStatus == kQ3Failure )
  98.         DebugStr("\pQ3Initialize returned failure.");            
  99.     
  100.     /*  initialize application globals */
  101.     
  102.     gQuitFlag = false;
  103.     gForeground = true;
  104.     gTicks        = 1;
  105.     /* load the application menu bar */
  106.     
  107.     menuBar = GetNewMBar( mBarResourceID );    /* Read menus into menu bar, MBAR res id is 128 */
  108.     
  109.     if ( menuBar == nil )
  110.          ExitToShell();                        /* if we dont have it then quit - your app */
  111.                                              /* needs a dialog here */
  112.  
  113.     SetMenuBar(menuBar);                    /* Install menus */
  114.     DisposHandle(menuBar);
  115.     
  116.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* Add DA names to Apple menu, ID 128 */
  117.  
  118.     Menu_Adjust() ;
  119.     DrawMenuBar();
  120. }
  121.  
  122.  
  123.  
  124. void Main_Destroy( void )
  125. {
  126.     Window_DestroyAll();
  127.     Q3Exit() ;
  128. }
  129.  
  130. /*    --------------------------------------------------------------------
  131. **    InitToolbox
  132. **    Initialize the toolbox managers
  133. */
  134. void InitToolbox( void )
  135. {
  136.     
  137.     InitGraf( &qd.thePort );
  138.     InitFonts();
  139.     InitWindows();
  140.     InitCursor();
  141.     InitDialogs( nil ) ;
  142.  
  143.     FlushEvents( everyEvent, 0 ) ;
  144. }
  145.  
  146.  
  147.  
  148. /*    --------------------------------------------------------------------
  149. **    Main_EventLoop
  150. **    The heart of the app. Handles all interaction
  151. */
  152. void Main_EventLoop()
  153. {
  154.     EventRecord     theEvent;
  155.     WindowPtr       theWindow;
  156.     short           thePart;
  157.     Rect            screenRect;
  158.     Point            aPoint = {100, 100};
  159.     Boolean            eventPresent = false;
  160.  
  161.     while( !gQuitFlag )
  162.     {
  163.         eventPresent = WaitNextEvent( everyEvent, &theEvent, gTicks, nil );
  164.         
  165.         if (eventPresent == true)
  166.         {
  167.             switch (theEvent.what) {
  168.                 case mouseDown:
  169.                 
  170.                     thePart = FindWindow( theEvent.where, &theWindow ) ;
  171.                     
  172.                     switch( thePart ) {
  173.                         case inMenuBar: 
  174.                             Menu_Adjust() ;
  175.                             Menu_HandleCommand(MenuSelect(theEvent.where));
  176.                             break;
  177.                         
  178.                         case inDrag:
  179.                             screenRect = (**GetGrayRgn()).rgnBBox;
  180.                             DragWindow( theWindow, theEvent.where, &screenRect );
  181.                             break ;
  182.                     
  183.                         case inContent:
  184.                             if (theWindow != FrontWindow())
  185.                                 SelectWindow( theWindow );
  186.                             Window_DoContent(theWindow, &theEvent);
  187.                             break ;
  188.                     
  189.                         case inGoAway:
  190.                             if (TrackGoAway( theWindow, theEvent.where )) {
  191.                                 Document_Delete( Document_GetFromWindow(theWindow) ) ;
  192.                             }
  193.                             break ;
  194.                             
  195.                         default:
  196.                             break ;
  197.                     }
  198.                     break ;
  199.                             
  200.                         
  201.                 case updateEvt:
  202.                 
  203.                     theWindow = (WindowPtr)theEvent.message;
  204.                     Window_Update( theWindow ) ;
  205.                     break ;
  206.                     
  207.                 case keyDown:
  208.                 case autoKey:
  209.                     Event_HandleKeyPress(&theEvent);
  210.                     break;
  211.                     
  212.                 case diskEvt:
  213.                     if ( Utility_HiWrd(theEvent.message) != noErr ) 
  214.                         (void) DIBadMount(aPoint, theEvent.message);
  215.                     break;
  216.                     
  217.                 case osEvt:
  218.                     Event_DoOSEvent(theEvent);
  219.                     break;
  220.  
  221.                 case activateEvt:
  222.                     break;
  223.             }
  224.         }
  225.         else {
  226.                 Event_DoNull();        /* Handle the Null Event */
  227.  
  228.         }
  229.     }
  230. }
  231.  
  232. /*    --------------------------------------------------------------------
  233. **    Main_DoAbout
  234. **    Display the About Box
  235. */
  236. void Main_DoAbout( void )
  237. {
  238.     short                itemHit ;
  239.     
  240.     itemHit = Alert ( 128, nil ) ;
  241. }